package com.java.controller;

import com.java.entity.PageBean;
import com.java.entity.PsLineInfo;
import com.java.entity.RespBean;
import com.java.service.PsLineInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

/**
 * @author caiyuan
 * @version 1.0
 * @Date 2020/6/24 11:38 Dream-Seeker
 * @Description
 */
@RestController
@RequestMapping("/lineinfo")
@Scope("prototype")
public class PsLineInfoController {
    @Autowired
    PsLineInfoService psLineInfoService;

    @GetMapping("/alllineinfo")
    public RespBean main(@RequestParam(value = "currentPage", defaultValue = "1", required = false) Integer currentPage,
                         @RequestParam(name = "runningStatusName") String runningStatusName,
                         @RequestParam(name = "lineCode") String lineCode) {
        try {
            runningStatusName = new String(runningStatusName.getBytes("ISO-8859-1"), "UTF-8");
            lineCode = new String(lineCode.getBytes("ISO-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        PageBean<PsLineInfo> list = psLineInfoService.findByPageLine(
                currentPage,
                runningStatusName,
                lineCode);//回显分页数据
        if (null != list) {
            return RespBean.ok("查询成功", list);
        } else {
            return RespBean.error("查询失败");
        }
    }

    @GetMapping("/runningchange")
    public RespBean runningchange(@RequestParam(name = "id") Integer id,
                                  @RequestParam(name = "isStart") Integer isStart) {
        Integer i = psLineInfoService.runningchange(id,isStart);
        if (i == 1) {
            return RespBean.ok("修改成功", i);
        } else {
            return RespBean.error("修改失败", i);
        }
    }
}
